package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Jl;
import com.ruoyi.system.service.IJlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 简历表Controller
 *
 * @author ruoyi
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/system/jl")
public class JlController extends BaseController
{
    @Autowired
    private IJlService jlService;
    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询简历表列表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:list')")
    @GetMapping("/list")
    public TableDataInfo list(Jl jl)
    {
        SysUser sysUser = getLoginUser().getUser();
        boolean contains3OR4OR9 = sysUser.getRoles().stream().anyMatch(v->v.getRoleId()==3L || v.getRoleId()==4L || v.getRoleId()==9L);
        if(contains3OR4OR9){
            jl.setDeptId(getDeptId());
        }
        startPage();
        List<Jl> list = jlService.selectJlList(jl);
        return getDataTable(list);
    }

    /**
     * 导出简历表列表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:export')")
    @Log(title = "简历表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Jl jl)
    {
        SysUser sysUser = getLoginUser().getUser();
        boolean contains3OR4OR9 = sysUser.getRoles().stream().anyMatch(v->v.getRoleId()==3L || v.getRoleId()==4L || v.getRoleId()==9L);
        if(contains3OR4OR9){
            jl.setDeptId(getDeptId());
        }
        List<Jl> list = jlService.selectJlList(jl);
        ExcelUtil<Jl> util = new ExcelUtil<Jl>(Jl.class);
        util.exportExcel(response, list, "简历表数据");
    }

    /**
     * 获取简历表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:jl:query')")
    @GetMapping(value = "/{jlId}")
    public AjaxResult getInfo(@PathVariable("jlId") Long jlId)
    {
        return success(jlService.selectJlByJlId(jlId));
    }

    /**
     * 新增简历表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:add')")
    @Log(title = "简历表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Jl jl)
    {
        SysUser sysUser = getLoginUser().getUser();
        boolean contains3OR4OR9 = sysUser.getRoles().stream().anyMatch(v->v.getRoleId()==3L || v.getRoleId()==4L || v.getRoleId()==9L);
        if(contains3OR4OR9){
            jl.setDeptId(getDeptId());
        }
        return toAjax(jlService.insertJl(jl));
    }

    /**
     * 修改简历表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:edit')")
    @Log(title = "简历表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Jl jl)
    {
        SysUser sysUser = getLoginUser().getUser();
        boolean contains3OR4OR9 = sysUser.getRoles().stream().anyMatch(v->v.getRoleId()==3L || v.getRoleId()==4L || v.getRoleId()==9L);
        if(contains3OR4OR9){
            jl.setDeptId(getDeptId());
        }
        return toAjax(jlService.updateJl(jl));
    }

    /**
     * 删除简历表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:remove')")
    @Log(title = "简历表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jlIds}")
    public AjaxResult remove(@PathVariable Long[] jlIds)
    {
        return toAjax(jlService.deleteJlByJlIds(jlIds));
    }

    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:jl:list')")
    @GetMapping("/deptTree")
    public AjaxResult deptTree(SysDept dept)
    {
        return success(deptService.selectDeptTreeList(dept));
    }
}
